package CutLoad.transitions
{
	import CutLoad.cookies.Painter;
	
	import com.greensock.*;
	import com.greensock.easing.*;
	import com.greensock.plugins.*;
	
	import flash.display.Bitmap;
	import flash.display.DisplayObject;

	/**
	 * 对目标进行放大或缩小缓动，并伴随着淡入淡出
	 * @author smallerbird mail:smallerbird@gmail.com  site:www.mkigm.com QQ群:49983196
	 * 下午01:44:58 
	 *
	 */
	public class UpDownAndAlphaInOut extends TBase
	{
		private var imgTarget:Bitmap;
		private var target:DisplayObject;
		private var TweenLite_easeIn:TweenLite;
		private var TweenLite_easeOut:TweenLite;
		/**
		 * 初始给 
		 * @param target 需要操作的目标
		 * @param delayFps 延时帧数
		 * 
		 */		
		public function UpDownAndAlphaInOut(target:DisplayObject,delayFps:Number=10)
		{
			super();
			if(target.parent==null) throw new Error("target.parent==null  !!!");
			TweenPlugin.activate([SetSizePlugin]);
			this.target=target;
			target.visible=false;
			rePhoto()
			imgTarget.visible=false;
		}
		private function rePhoto():void{
			if(imgTarget!=null){
				if(imgTarget.parent!=null){
					imgTarget.parent.removeChild(imgTarget);
				}
				imgTarget=null;
			}
			imgTarget=Painter.getImg(target);
			imgTarget.x=target.x;
			imgTarget.y=target.y;
			target.parent.addChild(imgTarget);
		}
		/**
		 * 获得模仿目标 
		 * @return 
		 * 
		 */		
		public function getTarget():DisplayObject{
			return this.target;
		}
		public function easeIn():void{
			target.visible=false;
			imgTarget.visible=true;
			imgTarget.width=1;
			imgTarget.height=1;
			imgTarget.alpha=0;
			TweenLite_easeIn=TweenLite.to(imgTarget, 1, {alpha:1,setSize:{width:target.width, height:target.height},ease:Back.easeOut,onComplete:easeIn_sizeOnComplete});
		}
		private function easeIn_sizeOnComplete():void{
			target.visible=true;
			imgTarget.visible=false;
		}
		public function easeOut():void{
			target.visible=false;
			imgTarget.visible=true;
			TweenLite_easeOut=TweenLite.to(imgTarget, 1, {alpha:0,setSize:{width:1, height:1},ease:Back.easeOut,onComplete:easeOut_sizeOnComplete});
		}
		private function easeOut_sizeOnComplete():void{
			//target.visible=true;
			//imgTarget.visible=false;
		}
		override public function stop(someData:TransitionsData=null):void{
			
		}
		override public function enterFrame():void{
			throw new Error("该方法禁用!!!");
		}
	}
}